extends NodeState

@export var zombie: Zombie

func _on_enter() -> void:
	if zombie and zombie.animated_sprite and not zombie.is_dead:
		zombie.animated_sprite.play("idle")

func _on_physics_process(_delta: float) -> void:
	pass

func _on_next_transitions() -> void:
	if not zombie or zombie.is_dead:
		if zombie and zombie.is_dead:
			transition.emit("die")
		return
	
	if not zombie.target_player:
		return
	
	var distance: float = zombie.get_distance_to_player()
	
	# 如果玩家在攻击范围内，切换到攻击状态
	if distance <= zombie.attack_range:
		transition.emit("attack")
	# 如果玩家在检测范围内但不在攻击范围内，切换到移动状态
	elif distance <= zombie.detection_range:
		transition.emit("walk")

func _on_exit() -> void:
	pass
